//
// This file is part of cpp-lib, a library of C++ functions and classes.
// Cpp-lib is copyright (C) 2004 and onwards, The CPL Interest Group.
// 
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or (at
// your option) any later version.
// 
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this library (see the file COPYING); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
// 02111-1307  USA
//
// $Id$
//

#include <iostream>
#include <iomanip>
#include <string>
#include <stdexcept>

#include "cpp-lib/util.h"
#include "cpp-lib/sys/file.h"


using namespace cpl::util::file ;
using namespace cpl::util       ;


int main() {

  try {

  std::string name ;
  std::cout << "Enter file name: " ;
  std::cin  >> name ;
  
  file_name_watcher fw( name ) ;

  long n ;
  std::cout << "Enter number of modified() calls: " ;
  std::cin  >> n ;

  double const t = utc() ;
  for( long i = 0 ; i < n ; ++i ) 
  { fw.modified() ; }

  double const tt = utc() ;

  std::cout << "Elapsed time: " << tt - t << " seconds." << std::endl ;
  std::cout << "Calls per second: " << n / ( tt - t ) << std::endl ;

  while( 1 ) {

	cpl::util::sleep( 1 ) ;

	std::cout << "File modified: " << fw.modified() << std::endl ;

  }

  } catch( std::exception const& e )
  { die( e.what() ) ; }

}
